In the session, Anne calculated the distances to the closest hospitals located within North-Rhine Westphalia (NRW). Still, she did not show how she subsetted the original file, which contains all hospitals in Germany. What did she do? Subset the data file yourself by relying on the spatial information of the csv-file “hospital_points” and the polygon of North-Rhine Westphalia.
data folder and a shapefile of NRW. For NRW, you can either use Stefans OSM syntax or use the “german_states” shapefile and filter on AGS=="05".
Row-wise deletion of observations with missing values will allow you to subset.
Did the operationalization of health care provision convince you? Don’t you think it might be more important how many hospitals are close to the respondents? To test this, we want to calculate the number of hospitals per district in North-Rhine Westphalia. Use the syntax below to load the district data and prep the hospital data.
Earn extra points by counting the number of hospitals and the sum of hospital beds within a district.
nrw_districts <- st_read(dsn = "./data",
layer = "GER_DISTRICTS",
quiet = T) %>%
st_transform(. , 3035) %>%
rename(., district_id = id) %>%
filter( district_id >= 5000 & district_id < 6000 )
nrw_hospitals <- nrw_hospitals %>%
mutate(beds = as.numeric(beds)) %>%
replace(., is.na(.), 0)
You need a as_tibble() data frame to use the functions group_by() and summarise().
The function n() allows summarising the total count of hospitals. sum(beds) for summarizing the sum of beds.